package jjn.round2;

import java.util.Arrays;

/**
 * @author Jiang Jining
 * @since 2023-05-13 0:29
 */
public class LeetCode2441_LargestPositiveWithNegative {
    public int findMaxK(int[] nums) {
        Arrays.sort(nums);
        int left = 0, right = nums.length - 1;
        while (left < right) {
            if (nums[left] + nums[right] == 0) {
                return nums[right];
            }
            if (nums[left] + nums[right] > 0) {
                right--;
            }
            if (nums[left] + nums[right] < 0) {
                left++;
            }
        }
        return -1;
    }
}
